package com.qf.business.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.business.entity.User;
import com.qf.business.mapper.UserMapper;
import com.qf.business.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author songfei
 * @Date 2021/10/5 15:47
 * @Version 1.0
 */
@Service
public class UserImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByName(String name) {

        return userMapper.selectByExample();
    }

    @Override
    public User findByNameAndPassword(String name, String password) {
        return null;
    }

    @Override
    public PageInfo<User> findByUserAndPage(Integer page, Integer rows, String name) {
        //1.分页
        PageHelper.startPage(page,rows);
        //2.查询
        List<User> userList = userMapper.findByName(name);
        //3.分装PageInfo
        PageInfo<User> pageInfo = new PageInfo<>(userList);
        //4.返回
        return pageInfo;
    }

    @Override
    public void updatePassword(User user) {
        int i = userMapper.updateByPrimaryKeySelective(user);
        if(i!=1){
            System.out.println("修改密码失败");
            throw new RuntimeException("修改密码失败");

        }
    }
}
